package com.hesicare.cgm.service.impl;

import com.hesicare.cgm.entity.CgmPatientGlucose;
import com.hesicare.cgm.enums.CgmEnum;
import com.hesicare.cgm.service.ICgmBloodGlucoseDayService;
import com.hesicare.cgm.service.ICgmBloodGlucoseService;
import com.hesicare.cgm.service.ICgmEquipmentService;
import com.hesicare.cgm.service.ICgmPatientBloodService;
import com.hesicare.config.cache.Cache;
import com.hesicare.health.entity.SysPatient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author 55097
 * @create 2021/12/6 12:48
 */
@Service
@Primary
public class CgmPatientBloodServiceImpl implements ICgmPatientBloodService {


    protected final static Logger log = LoggerFactory.getLogger(CgmPatientBloodServiceImpl.class);
    protected static Set<Object> CGMpatient = new HashSet<>();

    @Autowired
    private Cache cache;

    @Autowired
    private ICgmBloodGlucoseService cgmBloodGlucoseService;

    @Autowired
    private ICgmBloodGlucoseDayService cgmBloodGlucoseDayService;

    @Autowired
    private ICgmEquipmentService cgmEquipmentService;

    @Override
    public boolean getCGMpatientBlood(CgmPatientGlucose cgmPatientGlucose, SysPatient sysPatient) {
        if (CGMpatient.isEmpty()) {
            Set<Object> CGMpatientList = cache.getSetALL(CgmEnum.PATIENTLIST);
            if (CGMpatientList != null && !CGMpatientList.isEmpty()) {
                CGMpatient = CGMpatientList;
            }
        }
        cache.putSetValue(CgmEnum.PATIENTLIST, cgmPatientGlucose.getNumber());

        cgmEquipmentService.insertCgmEquipment(cgmPatientGlucose.getDeviceId(),sysPatient);
        cgmBloodGlucoseService.insertCgmBloodGlucose(cgmPatientGlucose, sysPatient);
        cgmBloodGlucoseDayService.insertCgmBloodGlucoseDay(cgmPatientGlucose, sysPatient);
        return true;
    }

}
